﻿using System.ComponentModel;
using System.Windows;

namespace Demos.Knapsack
{
    public abstract class ElementoVisual : DependencyObject
    {
        public double X
        {
            get { return (double)GetValue(XProperty); }
            set { SetValue(XProperty, value); }
        }

        // Using a DependencyProperty as the backing store for X.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty XProperty =
            DependencyProperty.Register("X", typeof(double), typeof(ElementoVisual), new UIPropertyMetadata(null));


        public double Y
        {
            get { return (double)GetValue(YProperty); }
            set { SetValue(YProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Y.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty YProperty =
            DependencyProperty.Register("Y", typeof(double), typeof(ElementoVisual), new UIPropertyMetadata(null));
    }

    public class Mochila : ElementoVisual,INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    
        private int _capacidad;
        public int Capacidad
        {
            get { return _capacidad; }
            set
            {
                _capacidad = value;
                NotifyPropertyChanged("Capacidad");
            }
        }

        private string _contenido;
        public string Contenido
        {
            get { return _contenido; }
            set
            {
                _contenido = value;
                NotifyPropertyChanged("Contenido");
            }
        }


        public Mochila(double x, double y, int capacidad)
        {
            X = x;
            Y = y;
            Capacidad = capacidad;
            Contenido = "";
        }
    }

    public class Objeto : ElementoVisual
    {
        public string Contenido { get; set; }
        public double Valor { get; set; }
        public int Peso { get; set; }

        public double Opacidad
        {
            get { return (double)GetValue(OpacidadProperty); }
            set { SetValue(OpacidadProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Opacidad.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty OpacidadProperty =
            DependencyProperty.Register("Opacidad", typeof(double), typeof(Objeto), new UIPropertyMetadata(null));


        public Objeto(double x, double y, string contenido, double valor, int peso)
        {
            X = x;
            Y = y;
            Contenido = contenido;
            Valor = valor;
            Peso = peso;
            Opacidad = 1;
        }
    }
}
